<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 1 333 22 幸运数
    let arr = [1, 3, 3, 3, 3, 4, 4, 4, 4, 4, 2, 2];
    function luck(arr) {
        let end = [];
        for (let index = 0; index < arr.length; index++) {
            let number = 0;
            for (let j = 0; j < arr.length; j++) {
                if (arr[index] == arr[j]) {
                    number++;
                }

            }
            end[arr[index]] = number;
        }
        let max = 0;
        for (let i = 0; i < end.length; i++) {
            if (end[i] == i) {
                if (end[i] > max) {
                    max = end[i];
                }
            }
        }
        // console.log(end);

        // 没错

        // for (let j = 0; j < end.length; j++) {
        //     if (max < end[j]) {
        //         max = end[j];
        //     }
        // }
        return max;
    }
    console.log(luck(arr))


</script>

</html>